package org.wekit.engine.pvm.runtime;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.wekit.engine.pvm.PvmActivity;
import org.wekit.engine.pvm.PvmExecution;
import org.wekit.engine.pvm.PvmProcessDefinition;
import org.wekit.engine.pvm.PvmProcessElement;
import org.wekit.engine.pvm.PvmProcessInstance;
import org.wekit.engine.pvm.PvmTransition;
import org.wekit.engine.pvm.delegate.ActivityExecution;
import org.wekit.engine.pvm.process.Activity;
import org.wekit.engine.pvm.process.ProcessDefinition;
import org.wekit.engine.pvm.process.Transition;
/**
 * 流程调度类
 * @author HuangWeili
 *
 */
public class ExecutionImpl implements InterpretableExecution,PvmExecution,Serializable{

	private static final long serialVersionUID = -2079141905615757380L;

	protected ProcessDefinition processDefinition;
	
	protected Activity activity;
	
	protected Transition transition=null;
	
	protected ExecutionImpl processInstance;
	
	protected ExecutionImpl parent;
	
	protected List<ExecutionImpl> executions;
	
	protected ExecutionImpl superExecution;
	
	protected ExecutionImpl subProcessInstance;
	
	
	protected boolean isActive=true;
	protected boolean isScope=true;
	protected boolean isConcurrent=false;
	protected boolean isEnded=false;
	
	//流程变量定义
	protected Map<String,Object> variables=null;
	
	protected String eventName;
	protected PvmProcessElement eventSource;
	protected int executionListenerIndex=0;
	
	
	
	//自动流程操作 atomic operations
	protected AtomicOperation nextOperation;
	protected boolean isOperating=false;
	
	public ExecutionImpl(){}

	/**
	 * 确保父节点已经初始化完毕
	 */
	protected void ensureParentInitialized(){
	}
	
	/**
	 * 确保变量已经初始化
	 */
    protected void ensureVariablesInitialized(){
    	if(null==variables)
    	{
    		variables=new HashMap<String, Object>();
    	}
    }
	
    /**
     * 初始化执行动作
     */
    protected void ensureExecutionsInitialized(){
    	if(null==this.executions){
    		this.executions=new ArrayList<ExecutionImpl>();
    	}
    }
    
    /**
     * 确认流程已经初始化
     */
    protected void ensureProcessDefinitionInitialized(){
    	
    }
    
    /**
     * 确认流程实例已经初始化
     */
    protected void ensureProcessInstanceInitialized(){
    	
    }
    
    /**
     * 确保Activity已经初始化
     */
    protected void ensureActivityInitialized(){
    	
    }
    
	public String toString()
	{
	  return null;
	}
    
	
	
	//VariableScope 接口实现
	@Override
	public Map<String, Object> getVariables() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getVariable(String variableName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Set<String> getVariableNames() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setVariable(String variableName, Object value) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setVariables(Map<String, ? extends Object> variables) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean hasVariables() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean hasVariable(String variable) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeVariables(String variable) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void clearVariables() {
		// TODO Auto-generated method stub
		
	}

	
	//ExecutionListenerExecution接口实现
	
	
	@Override
	public PvmProcessElement getEventSource() {
		// TODO Auto-generated method stub
		return null;
	}
	//DelegateExecution 接口

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getProcessinstanceId() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getEventName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getProcessBusinessKey() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
    //ActivityExecution

	@Override
	public PvmActivity getActivity() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ActivityExecution createExecution() {
		// TODO Auto-generated method stub
		return null;
	}

	
	protected ExecutionImpl newExecution(){
		return new ExecutionImpl();
	}
	
	@Override
	public PvmProcessInstance createSubProcessInstance(
			PvmProcessDefinition processDefinition) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ActivityExecution getParent() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<? extends ActivityExecution> getExecutions() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void end() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setActive(boolean isActive) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isActive() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEnded() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setConcurrent(boolean isConcurrent) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isConcourrent() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isProcessInstance() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void inactivate() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setScope(boolean isScope) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<ActivityExecution> findInactiveConcurrentExecutions(
			PvmActivity activity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void takeAll(List<PvmTransition> outgoingTransitions,
			List<ActivityExecution> joinedExecutions) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void executeActivity(PvmActivity activity) {
		// TODO Auto-generated method stub
		
	}
	//InterpretableExecution接口实现

	@Override
	public void take(PvmTransition transition) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEventName(String eventName) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEventSource(PvmProcessElement processElement) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getExecutionListenerIndex() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void setExecutionListenerIndex(int index) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ProcessDefinition getProcessDefinition() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setActivity(Activity activity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void performOperation(AtomicOperation atomicOperation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isScope() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initialize() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setProcessDefinition(ProcessDefinition processDefinition) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setProcessInstance(InterpretableExecution processInstance) {
		// TODO Auto-generated method stub
		
	}
	
	
	
   //PvmExecution接口实现

	@Override
	public void signal(String signalName, Object signalData) {
	}
	
	
	//PvmProcessInstance接口实现
	@Override
	public void start() {
		performOperation(new AtomicOperationProcessStart());
	}

	@Override
	public PvmExecution findExecution(String activityId) {
		return null;
	}

	@Override
	public List<String> findActiveActivityIds() {
		return null;
	}
	
	
	
}
